<%@page import="org.jeecgframework.web.util.StaticValue" %>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>派单</title>
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
    <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
    <link rel="stylesheet" href="plug-in/uploadify/css/uploadify.css" type="text/css"/>
    <script type="text/javascript" src="plug-in/uploadify/jquery.uploadify-3.1.min.js"></script>
    <script type="text/javascript" src="webpage/com/zybk/cbsservice/cbsServiceDispatchOrder.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#company').change(function () {
                if ($(this, "option:selected").val() != "") {
                    $.ajax({
                        url: "zyCommonController.do?queryTPServerBusinessr",
                        data: {
                            "orgCode": $(this).val(),
                            "contactPosition": '<%=StaticValue.DIC_CONTACT_POSITION_TP_SERVER_BUSINESSR%>'
                        },
                        cache: false,
                        dataType: 'json',
                        type: 'POST',
                        success: function (data) {
                            if (data.success) {
                                var obj = data.obj[0];
                                if (obj) {
                                    setContacters(obj.id, obj.name, obj.cellphone1 + (obj.cellphone2 == "" ? "" : ("/" + obj.cellphone2)), obj.email);
                                } else {
                                    setContacters();
                                }
                            }
                        }
                    });
                } else {
                    setContacters();
                }
            });

            //派单时回显  第三方服务单code
            var serviceProviderCode = '${serviceProviderCode}';
            var repairProvider = '${repairProvider}';
            var cbsId = '${cbsService.id}';
            var orgCode = '';
            if (repairProvider != null && repairProvider != '') {   //合同指定的，第一次回显
                $("select[name='company']").val(repairProvider);
                orgCode = repairProvider;
            }
            if (serviceProviderCode != null && serviceProviderCode != '') {   //服务单指派后的服务商，默认回显
                $("select[name='company']").val(serviceProviderCode);
                orgCode = serviceProviderCode;
            }
            if (orgCode != null && orgCode != '') {
                $.ajax({
                    url: "cbsServiceController.do?queryTPServerBusinessr",
                    data: {
                        "orgCode": orgCode,
                        "cbsId": cbsId,
                        "contactPosition": '<%=StaticValue.DIC_CONTACT_POSITION_TP_SERVER_BUSINESSR%>'
                    },
                    cache: false,
                    dataType: 'json',
                    type: 'POST',
                    success: function (data) {
                        if (data.success) {
                            var objects = data['attributes'].objects[0];
                            var obj = data['attributes'].zyContacts[0];
                            if (obj) {
                                if (typeof(objects) != "undefined" && objects != '') {
                                    setContacters(obj.id, obj.name, obj.cellphone1 + (obj.cellphone2 == "" ? "" : ("/"+obj.cellphone2)), (obj.email == "" ? "" : (obj.email)), (objects.assignDes == "" ? "" : (objects.assignDes)), (objects.dealWithTiem == "" ? "" : (objects.dealWithTiem)), (objects.authentication == "" ? "" : (objects.authentication)));
                                } else {
                                    setContacters(obj.id, obj.name, obj.cellphone1 + (obj.cellphone2 == "" ? "" : ("/"+obj.cellphone2)), (obj.email == "" ? "" : (obj.email)), '', '', '');
                                }

                            } else {
                                setContacters();
                            }
                        }
                    }
                });
            }
        });

        function setContacters(id, name, cellPhone, email, assignDes, dealWithTiem, authentication) {
            if (id == undefined || id == "") {
                $("#contacterId").val("");  //巡检负责人id
                $("#contacterName").html("");  //巡检负责人name
                $("#contacterCellPhone").html("");  //巡检负责人电话
                $("#contacterEmail").html(""); //巡检负责人email
            } else {
                $("#contacterId").val(id);
                $("#contacterName").html(name);
                $("#contacterCellPhone").html(cellPhone);
                $("#contacterEmail").html(email);
            }
        }
    </script>
</head>

<body>
<input type="hidden" name="cbsServiceId" value="${cbsService.id}" id="cbsServiceId">
<input type="hidden" name="changeStatus" value="${changeStatus}" id="changeStatus">
<input type="hidden" name="type" value="${type}" id="type">
<table class="nobordertable noborder" style="border: none;">
    <tbody>
    <tr>
        <td class="al_r" width="20%">
            <label>CR:</label>
        </td>
        <td width="70%">
            <span>${code}</span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>服务类型:</label>
        </td>
        <td width="70%">
            <span>${name}</span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>级别:</label>
        </td>
        <td width="70%">
            <span>${level}</span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label><label style="color: red;">*</label>服务商名称:</label>
        </td>
        <td width="70%">
            <span>
                <select name="company" id="company">
                    <option value="">---请选择--- </option>
                    <c:forEach items="${tsDeparts }" var="depart">
                        <option value="${depart.orgCode }">${depart.shortname }</option>
                    </c:forEach>
                </select>
            </span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label><label style="color: red;">*</label>负责人:</label>
        </td>
        <td width="70%">
            <input name="contacter.id" type="hidden" id="contacterId"/>
            <span id="contacterName"></span>
            &nbsp;&nbsp;&nbsp;
            <span id="contacterCellPhone"></span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>负责人邮箱:</label>
        </td>
        <td width="70%">
            <span id="contacterEmail"></span>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%">
            <label>工程师级别:</label>
        </td>
        <td width="70%">
            <t:dictSelect field="authentication" id="authentication" typeGroupCode="<%=StaticValue.DIC_CERTIFICATE %>" defaultVal="${cbsService.authentication}"/>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%" valign="top">
            <label>巴可HD处理过程:</label>
        </td>
        <td width="70%">
            <textarea style="width: 95%; height: 80px;" id="handleDes">${mmobj}</textarea>
        </td>
    </tr>
    <tr>
        <td class="al_r" width="20%" valign="top">
            <label><label style="color: red;">*</label>派单要求:</label>
        </td>
        <td width="70%">
            <textarea style="width: 95%; height: 80px;" id="assignDes"></textarea>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <table class="ftable">
                <tbody>
                <tr>
                    <th>选择</th>
                    <th>对象</th>
                    <th>待办内容</th>
                    <th>已分派次数</th>
                    <th>已完成次数</th>
                    <th>未完成次数</th>
                </tr>
                <c:forEach items="${attachTaskByCondition}" var="attach" varStatus="a">
                    <tr>
                        <td><input type="checkbox" value="${attach['id']}" id="att_${a.index}" <c:if test="${attach['isTrue'] eq '1'}"> checked="checked" </c:if> /></td>
                        <td>${attach['objectName']}</td>
                        <td>${attach['content']}</td>
                        <td>${attach['assignmentTotal']}</td>
                        <td>${attach['completeTotal']}</td>
                        <td>${attach['notCompleteTotal']}</td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </td>
    </tr>
    <tr>
        <td colspan="2" style="text-align: center;">
            <a onclick="saveDispatch()" class="easyui-linkbutton l-btn">确认</a>
        </td>
    </tr>
    </tbody>
</table>
</body>
</html>